char *str = "Hello world!\n";

void print()
{
	asm("mov $13, %%rdx \n\t"	/* rdx = length 13 */
		"mov %0, %%rcx \n\t"	/* rcx = str */
		"mov $0, %%rbx \n\t"	/* rbx = 0:stdout */
		"mov $4, %%rax \n\t"	/* rax = write 系统调用号为 4 */
		"int $0x80 \n\t"		/* write(0, str, 13) */
		:: "r"(str):"rdx", "rcx", "rbx");
}

void exit()
{
	asm("mov $42, %rbx \n\t"	/* rbx = 42, exit code */
		"mov $1, %rax \n\t"		/* rax = exit 系统调用号为 1 */ 
		"int $0x80 \n\t");		/* exit(42) */
}

void nomain()
{
	print();
	exit();
}

#if 0

// 使用普通命令行的方式来编译和链接:

	gcc -c -fno-builtin nomain.c
	ld -static -e nomain -o nomain nomain.o

// readelf -h nomain
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x401049
  Start of program headers:          64 (bytes into file)
  Start of section headers:          12848 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         10
  Section header string table index: 9

// write 
	int write(int filedesc, char *buffer, int size);

// objdump -S nomain
nomain:     file format elf64-x86-64

Disassembly of section .text:

0000000000401000 <print>:
  401000:	f3 0f 1e fa          	endbr64 
  401004:	55                   	push   %rbp
  401005:	48 89 e5             	mov    %rsp,%rbp
  401008:	53                   	push   %rbx
  401009:	48 8b 05 f0 2f 00 00 	mov    0x2ff0(%rip),%rax        # 404000 <str>
  401010:	48 c7 c2 0d 00 00 00 	mov    $0xd,%rdx
  401017:	48 89 c1             	mov    %rax,%rcx
  40101a:	48 c7 c3 00 00 00 00 	mov    $0x0,%rbx
  401021:	48 c7 c0 04 00 00 00 	mov    $0x4,%rax	
  401028:	cd 80                	int    $0x80	// 系统调用通过0x80中断实现,其中rax为调用号, rbx, rcx, rdx等通用寄存器用来传递参数
  40102a:	90                   	nop
  40102b:	5b                   	pop    %rbx
  40102c:	5d                   	pop    %rbp
  40102d:	c3                   	retq   

000000000040102e <exit>:
  40102e:	f3 0f 1e fa          	endbr64 
  401032:	55                   	push   %rbp
  401033:	48 89 e5             	mov    %rsp,%rbp
  401036:	48 c7 c3 2a 00 00 00 	mov    $0x2a,%rbx
  40103d:	48 c7 c0 01 00 00 00 	mov    $0x1,%rax
  401044:	cd 80                	int    $0x80
  401046:	90                   	nop
  401047:	5d                   	pop    %rbp
  401048:	c3                   	retq   

0000000000401049 <nomain>:
  401049:	f3 0f 1e fa          	endbr64 
  40104d:	55                   	push   %rbp
  40104e:	48 89 e5             	mov    %rsp,%rbp
  401051:	b8 00 00 00 00       	mov    $0x0,%eax
  401056:	e8 a5 ff ff ff       	callq  401000 <print>
  40105b:	b8 00 00 00 00       	mov    $0x0,%eax
  401060:	e8 c9 ff ff ff       	callq  40102e <exit>
  401065:	90                   	nop
  401066:	5d                   	pop    %rbp
  401067:	c3                   	retq   


#endif